package course.homework;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.bson.Document;


public class HashMapWrapper
{
	Map<String, Object> map = new HashMap<String,Object>();
	public HashMapWrapper()
	{
	}
	
	public void addAll(List<Document> docList)
	{
		for(Document doc : docList)
		{
			String temp = (new ArrayList<String>(doc.keySet())).get(0);
			String t;
			String s;
			if(temp.equals("type"))
			{
				t=temp;
				s=(new ArrayList<String>(doc.keySet())).get(1);
			}
			else
			{
				s=temp;
				t=(new ArrayList<String>(doc.keySet())).get(1);
			}
			addToMap(doc.getString(t), doc.getDouble(s));
		}
	}
	
	public void addToMap(String type, Double score)
	{
		boolean isPresent = map.containsKey(type);
		if(!isPresent  || score > (Double) map.get(type))
			map.put(type, score);
	}
	
	public List<Document> getDocument()
	{
		Iterator<String> keySet = map.keySet().iterator();
		String key1 = keySet.next();
		String key2 = keySet.next();
		String key3 = keySet.next();
		return Arrays.asList(new Document("type",key1).append("score", map.get(key1)),new Document("type",key2).append("score", map.get(key2)),new Document("type",key3).append("score", map.get(key3)));
	}
}